package com.heima.article.controller.v1;

import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.article.dtos.ArticleInfoDto;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api/v1/article")
@Api(tags = "加载文章列表")
public class ArticleHomeController {

    @Autowired
    private ApArticleService apArticleService;

    /**
     * app文章列表-加载首页
     * */
    @ApiOperation("加载首页")
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto){
        log.info("首页加载...");
//        return apArticleService.load(ArticleConstants.LOADTYPE_LOAD_MORE,dto);
        return apArticleService.loadFirst(ArticleConstants.LOADTYPE_LOAD_MORE,dto);
    }

    /**
     * app文章列表-加载更多
     * */
    @ApiOperation("加载更多")
    @PostMapping("/loadmore")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(ArticleConstants.LOADTYPE_LOAD_MORE,dto);
    }

    /**
     * app文章列表-加载最新
     * */
    @ApiOperation("加载最新")
    @PostMapping("/loadnew")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(ArticleConstants.LOADTYPE_LOAD_NEW,dto);
    }


    /*
    * 加载文章行为-数据回显
    * */
    @PostMapping("/load_article_behavior")
    public ResponseResult loadArticle(@RequestBody ArticleInfoDto dto){
        return apArticleService.loadArticle(dto);
    }
}
